<template>
  <div class="user">
    <!-- 1. 合同查看 -->
    <div class="hetong">
      签约合同内容：<el-button type="primary" size="small" @click="look"
        >查看合同</el-button
      >
    </div>
    <VuePdf ref="myPdf" />

    <!-- 2. 查看发票 -->
     <div class="money">
      <el-row :gutter="20">
        <el-col :span="8">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
              <span>卡片名称</span>
              <el-button @click="down" style="float: right; padding: 3px 0" type="text">下载发票</el-button>
            </div>
            <div class="text item">
              <img ref="img" style="width: 400px;" :src="imgUrl" alt=""/>
            </div>
          </el-card>
        </el-col>
        <el-col :span="8">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
              <span>卡片名称</span>
              <el-button @click="down" style="float: right; padding: 3px 0" type="text">下载发票</el-button>
            </div>
            <div class="text item">
              <img ref="img" style="width: 400px;" :src="imgUrl" alt=""/>
            </div>
          </el-card>
        </el-col>
        <el-col :span="8">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
              <span>卡片名称</span>
              <el-button @click="down" style="float: right; padding: 3px 0" type="text">下载发票</el-button>
            </div>
            <div class="text item">
              <img ref="img" style="width: 400px;" :src="imgUrl" alt=""/>
            </div>
          </el-card>
        </el-col>
      </el-row>
     </div>
  </div>
</template>

<script>
import VuePdf from './VuePdf.vue';
import img from '@/assets/images/11.jpg'
export default {
  data(){
    return{
      // imgUrl:require("../../assets/images/11.jpg")
      imgUrl:img
    }
  },
  components:{
    VuePdf
  },
  methods:{
    /**
     * 查看合同
     */
    look(){
      this.$refs.myPdf.dialogVisible=true
    },
    /**
     * 下载发票
     * 必须同源才能下载
     */
    down(){
      var alink = document.createElement("a");
      alink.href = this.imgUrl;
      console.log(this.imgUrl);
      alink.download = "pic"; //图片名
      alink.click();    
    }
  }
}
</script>

<style lang='less' scoped>
.user {
  margin: 10px;
}
.box-card{
  img{
    margin-left: 20px;
  }
}
</style>
